<?php

namespace app\api\controller\v2;

use app\common\controller\Frontend;
use think\facade\Db;
use think\facade\Log;

class Cooperation extends Frontend
{
    protected array $noNeedLogin = ['*'];
    protected array $noNeedPermission = ['*'];

    public function set ()
    {
        $data = $this->request->post();

        if (empty($data['name'])) {
            $this->error('姓名不能为空');
        }
        if (empty($data['phone'])) {
            $this->error('电话不能为空');
        }
        if (empty($data['code'])) {
            $this->error('验证码不能为空');
        }
        if (empty($data['region'])) {
            $this->error('意向城市不能为空');
        }
        try {
            sms_check($data['phone'], $data['code'], 'cooperation');
        } catch (\Exception $e) {
            Log::error('合作加盟-短信验证失败 ' . $e->getMessage());
            $this->error($e->getMessage());
        }
        $data['create_time'] = date('Y-m-d H:i:s', time());
        $ret = Db::name('cooperation')->insert($data);
        if (!$ret) {
            $this->error('提交失败');
        }
        $this->success('提交成功');
    }
}